<template>
  <van-action-sheet
    :show="userStore.showLoginDialog"
    :before-close="beforeClose"
    destroyOnClose
  >
    <NuxtImg
      src="/images/layout/icon-close2.png"
      class="close-icon"
      @click="beforeClose"
    />
    <div class="LoginRegister">
      <div class="LoginRegisterTab">
        <p :class="{ check: activeTab === 1 }" @click="activeTab = 1">
          <span>{{ lang.entrar_capital }}</span>
        </p>
        <p :class="{ check: activeTab === 2 }" @click="activeTab = 2">
          <span>{{ lang.registrar_capital }}</span>
        </p>
        <div class="box"></div>
      </div>
      <div class="LoginRegister-box">
        <div class="login_and_sign_input">
          <div class="input_box">
            <div class="label">
              <NuxtImg src="/images/layout/footer_1.png" />
            </div>
            <span class="qz">{{ phoneHeader }}</span
            ><input
              type="tel"
              v-model.trim="dataInfo.phone"
              maxlength="11"
              placeholder="Número de telefone (+55)"
              @input="validPhone"
            /><span v-if="showPhoneValid" class="tips_msg">{{
              lang.phone_valid
            }}</span>
          </div>
          <div class="input_box">
            <div class="label">
              <NuxtImg
                src="/images/layout/icon-LoginRegister_2.png"
              /><span></span>
            </div>
            <input
              v-model.trim="dataInfo.psd"
              :type="showPwd ? 'text' : 'password'"
              :placeholder="lang.psd_placeholder"
              @input="showPsdValid = false"
            />
            <div class="pwd" @click="showPwd = !showPwd">
              <NuxtImg v-if="showPwd" src="/images/layout/icon-pwd-01.png" />
              <NuxtImg v-else src="/images/layout/icon-pwd-02.png" />
            </div>
            <span v-if="showPsdValid" class="tips_msg">{{
              lang.psd_valid
            }}</span>
          </div>
        </div>
        <div class="forget_pwd">
          <span>{{ lang.forget_btn }}</span>
        </div>
        <div class="btn-box">
          <div class="registe_gift_box" v-show="activeTab === 2">
            <NuxtImg class="icon" src="/images/layout/register_gift2.png" />
            <div class="triangle"></div>
            <NuxtImg class="icon2" src="/images/layout/register_gift3.png" />
            <span class="text">{{ userStore.moneyUnit }} 4 ~ 134</span>
          </div>
          <div class="loginBtn heat_btn" v-click-move @click="login">
            <p v-if="activeTab === 1">{{ lang.entrar_capital }}</p>
            <p v-else>{{ lang.registro_btn }}</p>
          </div>
        </div>
        <p class="terms_service">
          {{ lang.login_tip }}
        </p>
      </div>
    </div>
  </van-action-sheet>
</template>

<script setup lang="ts">
const lang: any = getCurrentPageLang("system");

const phoneHeader = ref("+55");
const activeTab = ref(1);
const showPwd = ref(false);
const showPhoneValid = ref(false);
const showPsdValid = ref(false);

const userStore = useUserStore();
function beforeClose() {
  userStore.changeShowLogin(false);
}

const dataInfo = reactive({
  phone: "",
  psd: "",
});

function validPhone() {
  if (dataInfo.phone.length === 11) {
    showPhoneValid.value = false;
  }
}

watch(
  () => userStore.showLoginDialog,
  (newVal) => {
    if (!newVal) return;
    activeTab.value = userStore.showLoginType;
    dataInfo.phone = "";
    dataInfo.psd = "";
    showPhoneValid.value = false;
    showPsdValid.value = false;
  }
);

function login() {
  showPhoneValid.value = false;
  showPsdValid.value = false;
  if (dataInfo.phone.length < 11) {
    showPhoneValid.value = true;
  }
  if (!dataInfo.psd) {
    showPsdValid.value = true;
  }
  if (showPhoneValid.value || showPsdValid.value) return;

  userStore.changeIsLogin(true);
  userStore.changeShowLogin(false);
  console.log("登录");
}
</script>

<style scoped lang="scss">
.close-icon {
  position: absolute;
  top: -1rem;
  right: 0.3rem;
  width: 0.6rem;
  cursor: pointer;
}
.LoginRegister {
  background: linear-gradient(180deg, #ca55ae 0%, #3e2d4c 100%);
  border-top-left-radius: 0.5rem;
  border-top-right-radius: 0.5rem;
  padding-bottom: 1rem;
}
.LoginRegister .LoginRegisterTab {
  width: 100%;
  height: 1.4rem;
  margin-bottom: 0.3rem;
  display: flex;
  border-top-left-radius: 0.8rem;
  border-top-right-radius: 0.8rem;
  overflow: hidden;
  position: relative;
}
.LoginRegister .LoginRegisterTab .check {
  color: var(--theme-neutral1);
  position: relative;
}
.LoginRegister .LoginRegisterTab p {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 0.44rem;
  color: #f6a5d4;
  width: 50%;
  position: relative;
}
.LoginRegister .LoginRegisterTab * {
  transition: all 0.3s ease;
}
.LoginRegister .LoginRegisterTab .check:before {
  content: "";
  position: absolute;
  z-index: 2;
  bottom: 0rem;
  left: calc(50% - 1rem);
  width: 2rem;
  height: 0.1rem;
  border-radius: 0.04rem;
  background: var(--theme-neutral1);
  transition: left 0.5s ease-in-out;
}
.LoginRegister .LoginRegisterTab p span {
  position: relative;
  z-index: 3;
}
.LoginRegister .LoginRegisterTab * {
  transition: all 0.3s ease;
}
.LoginRegister .LoginRegisterTab .check:after {
  content: "";
  width: 0;
  height: 0;
  border-left: 0.25rem solid transparent;
  border-right: 0.25rem solid transparent;
  border-bottom: 0.25rem solid var(--theme-neutral1);
  position: absolute;
  bottom: 0.08rem;
  left: 50%;
  transform: translate(-50%);
  transition: all 0.5s ease-in-out;
  z-index: 2;
}
.LoginRegister .LoginRegisterTab p {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 0.44rem;
  color: var(--theme-neutral2);
  width: 50%;
  position: relative;
}
.LoginRegister .LoginRegisterTab * {
  transition: all 0.3s ease;
}
.LoginRegister .LoginRegisterTab p span {
  position: relative;
  z-index: 3;
}
.LoginRegister .LoginRegisterTab * {
  transition: all 0.3s ease;
}
.LoginRegister .LoginRegisterTab .box {
  width: 89%;
  height: 0.1rem;
  background: #f6a5d4;
  border-radius: 0.23rem;
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translate(-50%);
}
.LoginRegister .LoginRegisterTab * {
  transition: all 0.3s ease;
}
.LoginRegister .LoginRegister-box {
  padding: 0 0.5rem;
}
.LoginRegister .login_and_sign_input {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.3rem 0;
  margin-bottom: 0.15rem;
}
.LoginRegister .login_and_sign_input .input_box {
  height: 1.2rem;
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 0.4rem;
  background: #2c1d31;
  border-radius: 0.2rem;
  border: 0.03rem solid var(--border-color);
}
.LoginRegister .login_and_sign_input .input_box .label {
  width: 1rem;
  height: 100%;
  display: flex;
  align-items: center;
  position: relative;
}
.LoginRegister .login_and_sign_input .input_box .label:before {
  content: "";
  width: 0.04rem;
  height: 0.6rem;
  background: var(--border-color);
  border-radius: 0.2rem;
  position: absolute;
  right: 0;
}
.LoginRegister .login_and_sign_input .input_box .label img {
  width: 0.6rem;
}
.LoginRegister .login_and_sign_input .input_box .qz {
  color: var(--theme-neutral1);
  padding-left: 0.3rem;
}
.LoginRegister .login_and_sign_input .input_box input {
  height: 100%;
  width: 77%;
  font-size: 0.38rem;
  color: var(--theme-neutral1);
  background: transparent;
  padding-left: 0.3rem;
}
.LoginRegister .login_and_sign_input .input_box .tips_msg {
  position: absolute;
  bottom: -0.3rem;
  left: 0.1rem;
  color: red;
  font-size: 0.28rem;
}
.LoginRegister .login_and_sign_input .input_box .pwd {
  width: 0.6rem;
  height: 0.6rem;
}
.LoginRegister .login_and_sign_input .input_box .pwd img {
  width: 100%;
}
.LoginRegister .forget_pwd {
  margin-bottom: 1.2rem;
  text-align: left;
}
.LoginRegister .forget_pwd span {
  color: #ffa5da;
  font-size: 0.38rem;
}
.btn-box {
  position: relative;
  display: flex;
  justify-content: center;
}
.registe_gift_box {
  display: flex;
  align-items: center;
  color: var(--theme-neutral1);
  position: absolute;
  border-radius: 0.66rem;
  margin: 0 auto;
  right: 3rem;
  top: -0.85rem;
  .text {
    position: absolute;
    width: 3rem;
    left: 0.8rem;
    top: -0.37rem;
    font-size: 0.3rem;
  }
}
.icon {
  width: 0.8rem;
  z-index: 5;
}
.registe_gift_box .icon2 {
  width: 1.9rem;
  position: absolute;
  top: -0.45rem;
  left: 0.6rem;
}
.LoginRegister .loginBtn {
  width: 100%;
  height: 1.2rem;
  background: linear-gradient(270deg, #e150a4 0%, #e66fc8 81%);
  border-radius: 0.3rem;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 0.3rem;
}
.heat_btn {
  transition: all 0.3s ease-in-out;
}
.LoginRegister .loginBtn p {
  color: var(--theme-neutral1);
  font-size: 0.54rem;
  font-weight: 700;
}
.LoginRegister .terms_service {
  font-size: 0.34rem;
  font-weight: 800;
  color: #c18bb1;
  text-align: center;
  line-height: 0.5rem;
}
@keyframes move-a {
  0% {
    transform: translateY(0);
  }
  45% {
    transform: translateY(0.1rem);
  }
  55% {
    transform: translateY(0.1rem);
  }
  100% {
    transform: translateY(0);
  }
}
.move {
  animation: move-a 0.5s ease-out;
}
</style>
